package main

import "sync"

type ShardMap struct {
	mu        []sync.RWMutex
	m         []map[int]int
	ShardNum  int
	shardFunc func(key int) int
}

func NewShardMap(shardNum int, shardFunc func(key int) int) *ShardMap {
	m := new(ShardMap)
	// 分片 一个分片用一把锁
	m.mu = make([]sync.RWMutex, shardNum)
	m.m = make([]map[int]int, shardNum)
	for i := range m.m {
		m.m[i] = make(map[int]int, 0)
	}

	m.ShardNum = shardNum
	m.shardFunc = shardFunc

	return m
}
